import axios from 'axios'

// 创建axios对象
const service = axios.create({
  baseURL: 'http://127.0.0.1:8092', // 请求接口的域名
  // timeout: 9000 // 请求的超时
})

// 添加请求拦截器,
service.interceptors.request.use(
  request => {
    const token = localStorage.getItem('Authorization')
    if (token) {
      // 请求头携带token
      request.headers.Authorization = token
    }
    return request
  },
  error => {
    Promise.reject(error)
  }
)

// 添加响应拦截器
service.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    Promise.reject(error)
  }
)

export default service

